package org.example;

import com.alibaba.fastjson.JSONObject;
import redis.clients.jedis.Jedis;
import redis.clients.jedis.Transaction;

public class JedisContectTest2 {
    public static void main(String[] args) {
        Jedis jedis=new Jedis("127.0.0.1",6379);
        //开启事务
        Transaction multi =jedis.multi();

        JSONObject jsonObject=new JSONObject();
        jsonObject.put("hello","world");
        jsonObject.put("name","123");
        String user=jsonObject.toJSONString();
        try {
            multi.set("user", user);
            multi.exec();
        }catch (Exception e){
            multi.discard();
        }finally {
            System.out.println(jedis.get("user"));
            jedis.close();
        }
    }

}
